<?php
/********************************************************************
Product    : Plotalot
Date       : 7 August 2011
Copyright  : Les Arbres Design 2010-2011
Contact    : http://extensions.lesarbresdesign.info
Licence    : GNU General Public License
*********************************************************************/

defined('_JEXEC') or die('Restricted Access');

jimport('joomla.application.component.view');

require_once JPATH_COMPONENT.DS.'helpers'.DS.'view_helper.php';

class PlotalotViewTable extends JView
{
function display($tpl = null)
{
global $chart_types;

// the controller has already populated the data into $this->chart_data

	if ($this->chart_data->id < 1)					// creating a new record
		JToolBarHelper::title(LA_COMPONENT_NAME.': <small><small>'.JText::_('COM_PLOTALOT_NEW_TABLE').'</small></small>', 'plotalot.png');
	else
		JToolBarHelper::title(LA_COMPONENT_NAME.': <small><small>'.JText::_('COM_PLOTALOT_EDIT_TABLE').' '.$this->chart_data->id.'</small></small>', 'plotalot.png' );

	JToolBarHelper::apply();
	JToolBarHelper::save();
	JToolBarHelper::cancel();
		
// get component parameters
	
	$params = JComponentHelper::getParams(LA_COMPONENT);
	$trace = $params->get('trace',0);
	$tooltips = $params->get('tooltips',1);

	if ($params->get('autocomplete',1))
		$autocomplete = 'autocomplete="off"';
	else
		$autocomplete = '';

	if ($tooltips)
		{
		$chart_name_tooltip = 'title = "'.JText::_('COM_PLOTALOT_TOOLTIP_CHART_NAME').'"';
		$title_tooltip = 'title = "'.JText::_('COM_PLOTALOT_TOOLTIP_TITLE').'"';
		$db_name_tooltip = 'title = "'.JText::_('COM_PLOTALOT_TOOLTIP_DB_NAME').'"';
		$db_host_tooltip = 'title = "'.JText::_('COM_PLOTALOT_TOOLTIP_DB_HOST').'"';
		$db_user_tooltip = 'title = "'.JText::_('COM_PLOTALOT_TOOLTIP_DB_USER').'"';
		$db_pass_tooltip = $db_user_tooltip;
		$html_style_tooltip = 'title = "'.JText::_('COM_PLOTALOT_TOOLTIP_TABLE_HTML').'"';
		$html_odd_tooltip = 'title = "'.JText::_('COM_PLOTALOT_TOOLTIP_TABLE_ODD').'"';
		$html_even_tooltip = 'title = "'.JText::_('COM_PLOTALOT_TOOLTIP_TABLE_EVEN').'"';
		$max_rows_tooltip = 'title = "'.JText::_('COM_PLOTALOT_TOOLTIP_TABLE_MAX_ROWS').'"';
		$headings = 'title = "'.JText::_('COM_PLOTALOT_TOOLTIP_TABLE_HEADINGS').'"';
		$plot_query_tooltip = 'title = "'.JText::_('COM_PLOTALOT_TOOLTIP_TABLE_QUERY').'"';
		}
	else
		{
		$chart_name_tooltip = '';
		$title_tooltip = '';
		$db_name_tooltip = '';
		$db_host_tooltip = '';
		$db_user_tooltip = '';
		$db_pass_tooltip = '';
		$html_style_tooltip = '';
		$html_odd_tooltip = '';
		$html_even_tooltip = '';
		$max_rows_tooltip = '';
		$headings = '';
		$plot_query_tooltip = '';
		}

	?>
	<form action="index.php" method="post" name="adminForm" id="adminForm" <?php echo $autocomplete; ?> >

	<input type="hidden" name="option" value="<?php echo LA_COMPONENT; ?>" />
	<input type="hidden" name="id" value="<?php echo $this->chart_data->id; ?>" />
	<input type="hidden" name="chart_type" value="<?php echo $this->chart_data->chart_type; ?>" />
	<input type="hidden" name="task" value="" />
	<input type="hidden" name="controller" value="" />
	<?php echo JHTML::_('form.token'); ?>

	<table class="admintable">
	<tr>
		<td width="100" align="right" width="15%">
			<?php echo JText::_('COM_PLOTALOT_NAME'); ?>
		</td>
		<td>
			<?php 
			echo '<input class="text_area" type="text" name="chart_name" id="chart_name" size="40" 
			maxlength="250" '.$chart_name_tooltip.' value="'.htmlspecialchars($this->chart_data->chart_name).'" />';
			?>
		</td>
	</tr>

	<tr>
		<td width="100" align="right">
			<?php echo JText::_('COM_PLOTALOT_TITLE'); ?>
		</td>
		<td>
			<?php
			echo '<input class="text_area" type="text" name="chart_title" id="chart_title" size="150" maxlength="2000" '.$title_tooltip.' value="';
			echo htmlspecialchars($this->chart_data->chart_title).'" />';
			?>
		</td>
	</tr>

	<tr>
		<td width="100" align="right">
			<?php echo JText::_('COM_PLOTALOT_DATABASE'); ?>
		</td>
		<td>
				<?php
				echo '<input class="text_area" type="text" name="db_name" id="db_name" size="20" 
					maxlength="250" '.$db_name_tooltip.' value="'.
				htmlspecialchars($this->chart_data->db_name).'" />';
				echo ' '.JText::_('COM_PLOTALOT_HOST');
				echo ' <input class="text_area" type="text" name="db_host" id="db_host" size="20" 
					maxlength="250" '.$db_host_tooltip.' value="'.
				htmlspecialchars($this->chart_data->db_host).'" />';
				echo ' '.JText::_('COM_PLOTALOT_USER');
				echo ' <input class="text_area" type="text" name="db_user" id="db_user" size="20" 
					maxlength="250" '.$db_user_tooltip.' value="'.
				htmlspecialchars($this->chart_data->db_user).'" />';
				echo ' '.JText::_('COM_PLOTALOT_PASSWORD');
				echo ' <input class="text_area" type="password" name="db_pass" id="db_pass" size="20" 
					maxlength="250" '.$db_pass_tooltip.' value="'.
				htmlspecialchars($this->chart_data->db_pass).'" />';
				?>
		</td>
	</tr>

	<tr>
		<td width="100" align="right">
			<?php echo JText::_('COM_PLOTALOT_TABLE_STYLE'); ?>
		</td>
		<td>
			<?php
			echo '<input class="text_area" type="text" name="chart_css_style" id="chart_css_style" size="150" 
			maxlength="255" '.$html_style_tooltip.' value="'.htmlspecialchars($this->chart_data->chart_css_style).'" />';
			?>
		</td>
	</tr>

	<tr>
		<td width="100" align="right">
			<?php echo JText::_('COM_PLOTALOT_TITLE_ROW_STYLE'); ?>
		</td>
		<td>
			<?php
			echo '<input class="text_area" type="text" name="y_start" id="y_start" size="70" 
			maxlength="255" value="'.htmlspecialchars($this->chart_data->y_start).'" />';
			echo ' '.JText::_('COM_PLOTALOT_HEADING_ROW_STYLE');
			echo ' <input class="text_area" type="text" name="y_end" id="y_end" size="70" 
			maxlength="255" value="'.htmlspecialchars($this->chart_data->y_end).'" />';
			?>
		</td>
	</tr>

	<tr>
		<td width="100" align="right">
			<?php echo JText::_('COM_PLOTALOT_TABLE_ODD_STYLE'); ?>
		</td>
		<td>
			<?php
			echo '<input class="text_area" type="text" name="x_start" id="x_start" size="70" 
			maxlength="255" '.$html_odd_tooltip.' value="'.htmlspecialchars($this->chart_data->x_start).'" />';
			echo ' '.JText::_('COM_PLOTALOT_TABLE_EVEN_STYLE');
			echo ' <input class="text_area" type="text" name="x_end" id="x_end" size="70" 
			maxlength="255" '.$html_even_tooltip.' value="'.htmlspecialchars($this->chart_data->x_end).'" />';
			?>
		</td>
	</tr>

	<tr>
		<td width="100" align="right">
			<?php echo JText::_('COM_PLOTALOT_MAX_ROWS'); ?>
		</td>
		<td>
			<?php
			echo '<input class="text_area" type="text" name="y_size" id="y_size" size="10" 
			maxlength="10" '.$max_rows_tooltip.' value="'.$this->chart_data->y_size.'" />';
			echo ' ';
			echo LA_view::make_checkbox('legend_type', $this->chart_data->legend_type,JText::_('COM_PLOTALOT_COL_HEADINGS'),$headings);
			?>
		</td>
	</tr>

	<tr>
		<td width="100" align="right" valign="top">
			<?php echo JText::_('COM_PLOTALOT_QUERY'); ?>
		</td>
		<td>
			<?php
			if (isset($this->chart_data->plot_array[0]['query']))
				$query = $this->chart_data->plot_array[0]['query'];
			else
				$query = '';
			echo '<textarea name="plot_query_0" rows="6" cols="100" '.$plot_query_tooltip.' >'.htmlspecialchars($query).'</textarea>';
			?>
		</td>
	</tr>
	</table>
	<div class="clr"></div>

	</form>
	<?php
		
	// if not new, try to draw the chart
	
	if ($this->chart_data->id > 0)
		{
		$plotalot = new Plotalot;
		$chart_html = $plotalot->drawChart($this->chart_data,$trace);
	if ($plotalot->error != '')
		echo '<div class="plotalot_error">'.JText::_('COM_PLOTALOT_ERROR').': '.$plotalot->error.'</div>';
	if ($plotalot->warning != '')
		echo '<div class="plotalot_error">'.JText::_('COM_PLOTALOT_WARNING').': '.$plotalot->warning.'</div>';
		echo $chart_html;
		}	
}
}